﻿
@{
    ViewBag.Title = "工作汇报";
    Layout = "~/Views/Shared/_indexBase1.5.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery-2.0.3.js"></script>
        <script src="~/LiberUI/Scripts/jquery.ba-resize.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Controllers.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
        <script src="~/SiteUI/BaseScripts/site.js"></script>
    }
    <link href="~/SiteUI/Base.css" rel="stylesheet" />
    <link href="~/SiteUI/WorkReport/WorkReport.css" rel="stylesheet" />
}
@*临时容器，放置需动态展现的自定义页面部件*@
<div id="tmp">
    @RenderPage("/SiteUI/wgBase.cshtml")
    <div id="SaveEnd">
        <h1>成功</h1>
        <h2>您的周报已永久存档，接下来，你还可以...</h2>
        <a id="PreviewIt" href="#" target="_blank">预览</a>
        <a id="SaveIt" onclick="SaveReport()">下载</a>
    </div>
</div>

@section HeadCnt{
    <div class="MiddleWraper">
        <h2 class="index_Title">@ViewBag.Title</h2>
        <a class="SubIndex" href="#">我的汇报</a>
        <a class="SubIndex" href="#">团队汇报</a>
    </div>
}

@section HeadBar{
    <div id="Tools" class="LeftWraper">
        <div id="Add">创建周报</div>
    </div>
}

@section LeftNavi{
    <h3>历史存档：</h3>
    <div id="lstHistory">

    </div>
}
<div id="pnlWorkspace">
    <h4>模式内容</h4>
    <h4>历史存档查看</h4>
    <h4>编辑区</h4>
</div>
<div id="btnGetReport">下一步：生成周报</div>

<script>
    function beginWeeklyReport() {
        $("#pnlWorkspace").html('').load('/WorkReport/NewWeeklyReport', null, function () { $("#btnGetReport").show();});
    };

    function saveReport() {
        $("#pnlWorkspace>script").remove();
        $("#pnlWorkspace .placeholder").remove();
        $(".editble").removeClass('editble').removeAttr('contenteditable');
        
        var cnt = $("#pnlWorkspace")[0].innerHTML;
        var name = '@ViewBag.ReportName';
        //TODO:显示默认文件名，并允许修改
        //TODO:弹出对话框用于等待和回显结果

        //TODO:将内容传递到后台，生成静态html文件
        var pop = new Dialoger(true).Content(Env.aniWaiting.show());
        pop.show();
        new AjaxHelper('post', '/WorkReport/SaveReport', { content: cnt }, saveEnd, pop);
    };

    function saveEnd(rtn, dialog) {
        if (rtn.IsPositive) {
            dialog.Content($("#SaveEnd").clone().show()).BtnEsc('关闭',EndStep);
            $("#PreviewIt").attr('href', rtn.Data.FileUrl);
            $("#lstHistory").append($("<a target='_blank'>").text(rtn.Data.FileName).attr('href', rtn.Data.FileUrl));
        }
    };

    function getFileName() {

    };

    function SaveReport() {
        var urls=$("#PreviewIt").attr('href').split('\\');
        window.open("/WorkReport/Download?filename="+urls[urls.length-1]);
    };

    function EndStep() {
        $("#pnlWorkspace").html('');
        $("#btnGetReport").hide();
    };

    $(function () {
        $("#Add").on('click', beginWeeklyReport);
        $("#btnGetReport").on('click', saveReport);
        new Button($("#btnCloseDialog")).on('click', function () { $('body').Unmask(); });
    });
</script>
